// Copyright (c) Microsoft Corporation.  All rights reserved.

#include "stdafx.h"
#include "D3D10ShaderReflectionConstantBuffer.h"

#include "D3D10ShaderReflectionVariable.h"

using namespace Microsoft::WindowsAPICodePack::DirectX::Direct3D10;
using namespace msclr::interop;

ShaderBufferDescription^ ShaderReflectionConstantBuffer::GetDescription()
{
    ShaderBufferDescription^ desc = gcnew  ShaderBufferDescription();
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflectionConstantBuffer>()->GetDesc(desc->nativeObject.Get()));
    return desc;
}

ShaderReflectionVariable^ ShaderReflectionConstantBuffer::GetVariableByIndex(UInt32 index)
{
    ID3D10ShaderReflectionVariable* returnValue = GetInterface<ID3D10ShaderReflectionConstantBuffer>()->GetVariableByIndex(static_cast<UINT>(index));
    return returnValue == NULL ? nullptr : gcnew ShaderReflectionVariable(returnValue);
}

ShaderReflectionVariable^ ShaderReflectionConstantBuffer::GetVariableByName(String^ name)
{
    marshal_context^ context = gcnew marshal_context();
    ID3D10ShaderReflectionVariable* returnValue = GetInterface<ID3D10ShaderReflectionConstantBuffer>()->GetVariableByName(context->marshal_as<const char*>(name));
    return returnValue == NULL ? nullptr : gcnew ShaderReflectionVariable(returnValue);
}

